const jQuery = require('jquery');
const path = require('path');
const epointajax = require(path.join(__dirname, '../../../js/epointajax'));
const common = require(path.join(__dirname, '../../../js/common'));
const {
  allconfig
} = require(path.join(__dirname, '../../../js/config'));
const {
  ipcRenderer
} = require('electron');


var pagevue;
jQuery(function ($) {

  var appguid = common.UrlParm.parm('appguid');

  //获取应用基本信息
  epointajax.post(allconfig.serverurl + '/rest/toolsrest/appinfo_detail', {
    appguid: appguid
  }).then((retinfo) => {
    var appinfo = retinfo.custom;

    initPage(appinfo);

  }).catch(msg => {
    console.log(msg);
  });

  function initPage(appinfo) {
    //渲染列表
    pagevue = new Vue({
      el: '#app',
      data: function () {
        return {
          form: {
            iconurl: appinfo.iconurl,
            appname: appinfo.appname,
            appurl: appinfo.appurl,
            operateusername: appinfo.operateusername,
            remark: appinfo.remark,
            collect: appinfo.collect
          }
        }
      },
      methods: {
        closepage() {
          ipcRenderer.send('initAppdetail');
          window.close();

        },
        appdetailadd() {
          epointajax.post(allconfig.serverurl + '/rest/toolsrest/appdetail_add', {
            appguid: appguid
          }).then((retinfo) => {
            if (retinfo.status) {
              this.$message({
                message: retinfo.text,
                type: 'success'
              });
              this.form.collect = true;
            }
          }).catch(msg => {
            console.log(msg);
          });
        },
        appdetaildelete() {
          epointajax.post(allconfig.serverurl + '/rest/toolsrest/appdetail_delete', {
            appguid: appguid
          }).then((retinfo) => {

            if (retinfo.status) {
              this.$message({
                message: retinfo.text,
                type: 'warning'
              });
              this.form.collect = false;

            }
          }).catch(msg => {
            console.log(msg);
          });
        }
      }

    });
  }


});
